package com.quanyan.comment.utils;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * Created by Administrator on 2016/5/26.
 */
public class ValidUtils<T> {

    public  List<String> getListMessage(T t){
        ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
        Validator validator = vf.getValidator();
        Set<ConstraintViolation<T>> set = validator.validate(t);
        if(set.size()< 0)
            return null;
        List<String> lsgMsg = new ArrayList<String>();
        for (ConstraintViolation<T> constraintViolation : set) {
            lsgMsg.add(constraintViolation.getMessage());
        }
        return lsgMsg;
    }
}
